<?php
namespace Admin\Controller;
use Think\Controller;
use Admin\Common\Api\UserApi;
class ImgController extends BaseController {
    private $adminUser = null;
    public function _initialize(){
    	parent::_initialize();
    	$this->adminUser = new UserApi();

    }
	//获取后台管理员的信息
    public function index(){
      $this->display();
    }

   public function img_list(){
          $title =I('request.title','','trim');
        if(!empty($title)){
           $where['name'] =array('like',"%{$title}%");
           // print_r($_where);exit;
           // $_where['parcelname']=array('like',"%{$keywords}%");
        }
         $where['is_activity'] = 1;
        $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = '*';
        $_where_order_field["order"] = 'id desc';
        $_datalist= $this->_getListsFromModel('Type',$_where_order_field);
        // print_r($_datalist['page_html']);exit;
        $this->assign('lists',$_datalist);
        $this->display();
   } 

    //获取后台管理员的信息
    public function images(){
      $this->display();
    }

   public function images_list(){
          $title =I('request.title','','trim');
        if(!empty($title)){
           $where['name'] =array('like',"%{$title}%");
           // print_r($_where);exit;
           // $_where['parcelname']=array('like',"%{$keywords}%");
        }
         $where['a.is_activity'] = 1;
        $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = 'a.*,u.name as user_name';
        $_where_order_field["order"] = 'id desc';
        $_where_order_field["alias"] = 'a';
        $_where_order_field["join"]=array("inner join song_user u on a.u_id=u.id"); 

        $_datalist= $this->_getListsFromModel('Images',$_where_order_field);
        // print_r($_datalist['page_html']);exit;
        $this->assign('lists',$_datalist);
        $this->display();
   } 



     public  function delete_images_ok(){
        $id=I("request.id");
        $auth_ruleModel=M("Images");
        $auth_ruleModel->where(array("id"=>$id))->delete();
        // $this->success("删除成功！");
         $this->ajaxReturn(array('status'=>1,'info'=>'删除成功！'));
  }

     public function del_images_all(){
      if(IS_POST){
        $allid = I('post.allid');
        $where = "id in (".$allid.")";
          $row = D('Images')->where($where)->delete();
             if($row != flase){
                  $ret=array('state'=>'1','msg'=>"批量删除成功!");
             }else{
                 $ret=array('staute'=>'0','msg'=>"批量删除失败！");
             }
        }else{
            $ret=array('staute'=>'0','msg'=>"批量删除失败,信息传递错误！");
        }

        //echo D('group_purchase')->getLastSql();

     $this->ajaxReturn($ret);



   }



       //获取后台管理员的信息
    public function user_img(){
      $this->display();
    }

   public function user_img_list(){
          $title =I('request.title','','trim');
        if(!empty($title)){
           $where['name'] =array('like',"%{$title}%");
           // print_r($_where);exit;
           // $_where['parcelname']=array('like',"%{$keywords}%");
        }
         $where['is_activity'] = 1;
        $_where_order_field["listrows"] =I("request._listrows");
        $_where_order_field["where"] = $where;
        $_where_order_field["field"] = '*';
        $_where_order_field["order"] = 'id desc';
        $_datalist= $this->_getListsFromModel('User',$_where_order_field);
        foreach ($_datalist['lists'] as $key => $value) {
          $img_list = D('Images')->where('u_id = '.$value['id'])->select();
          if($img_list){
            $value['img_list'] = $img_list;
            $_datalist['lists'][$key] = $value;
          }
        }
        $this->assign('lists',$_datalist);
        $this->display();
   } 



//同步图片
   public function sync_picture(){
      $id =I('request.id','','trim');
      $this->assign('id',$id);
      $this->display();
   }

 public function start_sync_picture(){
      $id =I('request.id','','trim');
      $url = I('request.url','','trim');
       // echo '/www/xuexi/test.py '.$url.' '.$id ; exit;
      // system(" C:\Users\Administrator\Desktop\test.py");
      // $url_name_arr =  system('D:\WWW\xuexi\test.py '.$url.' '.$id);
      $url_name_arr =  system('python /www/xuexi/test.py "'.$url.'" '.$id);
      // $arr = array();
      // exec('/usr/bin/python2 /www/xuexi/test.py 2>&1 '.$url.' '.$id,$arr,$state);
       // exec(' /www/xuexi/test.py '.$url.' '.$id,$arr,$state);
       $exe_scriptstr = "<script>
                    setTimeout(function(){
                    var win=    art.dialog.opener;
                                win.load();
                                art.dialog.close();
                    },1000);
           </script>";
      if($state==0){
         $this->success("同步成功！".$exe_scriptstr);
      }else{
                $this->error("添加失败！");
      }

   }
}
